package org.example.mine.controller;

import org.example.mine.service.MyWalletService;
import org.example.model.common.Result;
import org.example.model.domain.express.ExpressDetial;
import org.example.model.domain.express.ExpressList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/mywallet")
public class MyWalletController {

    @Autowired
    MyWalletService MyWalletService;
    @GetMapping("/getuserbyId/{id}")
    public ExpressList getUserbyId(@PathVariable("id") Integer id){
        return MyWalletService.getUserbyId(id);
    }
    @GetMapping("/getuserdetail/{registerIp}")
    public ExpressDetial getuserdetail(@PathVariable("registerIp") String id){
        return MyWalletService.getuserdetail(id);
    }
    @GetMapping("/withhold/{registerIp}/{balance}/{id}")
    public Result withhold(@PathVariable("registerIp") Long registerIp, @PathVariable("balance") BigDecimal balance,@PathVariable("id") Integer id){
        Integer num=MyWalletService.withhold(registerIp,balance);
        if(num==1){
            MyWalletService.updatestate(id,"2");
        }else{
            MyWalletService.updatestate(id,"3");
        }
        return Result.build(200,"扣款成功");
    }
}
